#! /usr/bin/python
import os, sys, json
from BeautifulSoup import BeautifulSoup

sys.path.append('/home/luanjunyi/poseidon/')

from util import pbrowser

print "Content-type: application/json\n\n"

output = {}
query = os.environ['QUERY_STRING']
query = dict(i.split('=') for i in query.split('&'))
url = query['url']
br = pbrowser.get_browser()
html = br.open(url).read()
soup = BeautifulSoup(html)
output['title'] = soup.title.string

desc = soup.find(attrs={'name': 'description'})
if desc and desc.has_key('content'):
    output['desc'] = desc['content']
else:
    output['desc'] = 'Your story here...'

print json.dumps(output)



